$(function(){
	
	$("#batchAddStudentBtn").click(function(){
		$("#uploadFileModal").modal("show");
	});
	$("#uploadAddStudent").on("click", function(){
		$.ajaxFileUpload({
			url: 'upload',
			secureuri: false,
			fileElementId:'uploadFile',
			dataType: 'json',
			success: function(data){
				if(data.success){
					alert("批量导入成功！");
					location.reload();
				}else{
					alert(data.messageMap.message);
				}
				location.reload();
			},
			error: function(data){
				alert(data.messageMap.message);
			}
		});
		
		
		
	});
	
	//上传样式
	$('#uploadFile').ace_file_input({
        style: 'well',
        btn_choose: 'Drop files here or click to choose',
        btn_change: null,
        no_icon: 'ace-icon fa fa-cloud-upload',
        droppable: true,
        thumbnail: 'small'
        ,
        preview_error: function (filename, error_code) {
        }
    }).on('change', function () {

    });
	
	
	$("#addStudent").on('click', function(){
		$("#addStudentModal").modal("show");
	});
	$("#addStudentBtn").click(function(){
		var userId = $("#userId").val();
		var userName = $("#userName").val();
		var gender = $("#gender").val();
		var address = $("#address").val();
		var tel = $("#tel").val();
		var password = $("#password").val();
		var email = $("#email").val();
		var birthday = $("#birthday").val();
		if(userId!=""){
			if(userName!=""){
				if(password!=""){
					if(birthday!=""){
						if(address!=""){
							if(tel!=""){
								if(email!=""){
									$.ajax({
										type: 'POST',
										url: 'add',
										data:{
											"userId":userId,
											"userName":userName,
											"gender":gender,
											"address":address,
											"tel":tel,
											"password":password,
											"email":email,
											"birthday":birthday
											},
										dataType: "json",
										success:function(date){
											alert(date.massage);
											location.reload();
										}
									});
								}else{
									$("#emails").text("邮箱不能为空！");
								}
							}else{
								$("#tels").text("电话不能为空！");
							}
						}else{
							$("#addresss").text("地址不能为空！");
						}
					}else{
						$("#birthdays").text("出生年月不能为空！");
					}
				}else{
					$("#passwords").text("密码不能为空！");
				}
			}else{
				$("#userNames").text("姓名不能为空！");
			}
		}else{
			$("#userIds").text("ID不能为空！");
		}
	});
	
	$(".editStudent").click(function(){
		var userId = $(this).parent().siblings().eq(0).text();
		$.ajax({
			type: 'POST',
			url: 'toEdit',
			data:{
				"userId":userId
				},
			dataType: "json",
			success:function(date){
				$("#userIdedit").val(date.userId);
				$("#userNameedit").val(date.userName);
				$("#genderedit").val(date.gender);
				$("#addressedit").val(date.address);
				$("#teledit").val(date.tel);
				$("#emailedit").val(date.email);
				$("#birthdayedit").val(date.birthday);
			}
		});
		$("#editStudentModal").modal("show");
	});
	
	$("#edistStudentBtn").click(function(){
		var userId = $("#userIdedit").val();
		var userName = $("#userNameedit").val();
		var gender = $("#genderedit").val();
		var address = $("#addressedit").val();
		var tel = $("#teledit").val();
		var email = $("#emailedit").val();
		var birthday = $("#birthdayedit").val();
			if(userName!=""){
					if(birthday!=""){
						if(address!=""){
							if(tel!=""){
								if(email!=""){
									$.ajax({
										type: 'POST',
										url: 'edit',
										data:{
											"userId":userId,
											"userName":userName,
											"gender":gender,
											"address":address,
											"tel":tel,
											"email":email,
											"birthday":birthday
											},
										dataType: "json",
										success:function(date){
											alert(date.massage);
											location.reload();
										}
									});
								}else{
									$("#emails1").text("邮箱不能为空！");
								}
							}else{
								$("#tels1").text("电话不能为空！");
							}
						}else{
							$("#addresss1").text("地址不能为空！");
						}
					}else{
						$("#birthdays1").text("出生年月不能为空！");
					}
			}else{
				$("#userNames1").text("姓名不能为空！");
			}
		
	});
});